package com.poorstu.manager.impl;

import java.util.ArrayList;
import java.util.List;

import com.poorstu.dao.LoginDao;
import com.poorstu.dao.PartTimeDao;
import com.poorstu.dao.StudentDao;
import com.poorstu.manager.StudentManager;
import com.poorstu.model.AuditLoadMod;
import com.poorstu.model.AuditsMod;
import com.poorstu.model.ClassMod;
import com.poorstu.model.CollegeMod;
import com.poorstu.model.HmenberMod;
import com.poorstu.model.HomeMod;
import com.poorstu.model.LoadMod;
import com.poorstu.model.LoadMoneyMod;
import com.poorstu.model.LoginMod;
import com.poorstu.model.PartTimeMod;
import com.poorstu.model.StudentMod;
import com.poorstu.model.UserPartTimeMod;

public class StudentManagerImpl implements StudentManager{
	
	StudentDao studentDao;
    LoginDao loginDao;
    PartTimeDao partTimeDao;
    
    
	public void addPtApply(UserPartTimeMod applyPartTime,int allUserId,int jobId) {
		
		LoginMod userMod=loginDao.selectUserById(allUserId);
		
		PartTimeMod partMod=partTimeDao.selectPartTimeById(jobId);
		applyPartTime.setUser(userMod);
		applyPartTime.setPts(partMod);
		
		studentDao.addStuApplu(applyPartTime);
	}

	
	// 进入到学生会审核学生助学岗位申请的管理页

	public List<UserPartTimeMod> selectUserPart() {
		try{
			
			List<UserPartTimeMod> newUserPartTimeList =new ArrayList<UserPartTimeMod>();
			List<UserPartTimeMod> userPartTimeList =new ArrayList<UserPartTimeMod>();
			
			userPartTimeList=studentDao.selectUserPart();
			
			
			
			for(int i=0;i<userPartTimeList.size();i++){
				UserPartTimeMod up = new UserPartTimeMod();
				PartTimeMod partMod=new PartTimeMod();
			//	UserPartTimeMod uptm=new  UserPartTimeMod();
				
				partMod.setCompany(userPartTimeList.get(i).getPts().getCompany());
				partMod.setMoney(userPartTimeList.get(i).getPts().getMoney());
				
				//uptm.setParStatus(parStatus)
				
				LoginMod loginMod=new LoginMod();
				//循环到i=2时报错
				loginMod.setName(userPartTimeList.get(i).getUser().getName());
			
				up.setParStatus(userPartTimeList.get(i).getParStatus());
				up.setUser(loginMod);
				up.setPts(partMod);
				up.setUspartId(userPartTimeList.get(i).getUspartId());
				newUserPartTimeList.add(up);
			}
		
			return newUserPartTimeList;
		}catch(Exception e)
		{
			e.printStackTrace();
			return null;
		}
	}

	


	//返回给学生会审批学生申请的助学岗位页
	public UserPartTimeMod selectUserPartTime(int userPartTimeId) {
		
		UserPartTimeMod newUserPart=new UserPartTimeMod();
		LoginMod login=new LoginMod();
		StudentMod stuMod=new  StudentMod();
		PartTimeMod pt=new PartTimeMod();
		
		UserPartTimeMod userPart=studentDao.selectUserPartTimeById(userPartTimeId);
		int jobId=userPart.getPts().getJobId();
		
		int applyPassNumber=studentDao.countApplyPartTimeNumber(jobId).size();
		
		int applyNumber=studentDao.countApplyNumber(jobId).size();
		
	//	int allUserId=userPart.getUser().getId();
	//	login =loginDao.selectUserById(allUserId);
		
		 stuMod.setStuName(userPart.getUser().getStu().getStuName());
		 
		 stuMod.setAges(userPart.getUser().getStu().getAges());
		 stuMod.setSchool(userPart.getUser().getStu().getSchool());
		 stuMod.setNation(userPart.getUser().getStu().getNation());
		 stuMod.setSex(userPart.getUser().getStu().getSex());
		 stuMod.setUserId(userPart.getUser().getStu().getUserId());
		 stuMod.setResidents(userPart.getUser().getStu().getResidents());
		 stuMod.setSpeciality(userPart.getUser().getStu().getSpeciality());
		 stuMod.setStudentId(userPart.getUser().getStu().getStudentId());
		 login.setStu(stuMod);
		 
		 pt.setCompany(userPart.getPts().getCompany());
		 pt.setConPhone(userPart.getPts().getConPhone());
		 pt.setContactName(userPart.getPts().getContactName());
		 pt.setContent(userPart.getPts().getContent());
		 pt.setEmile(userPart.getPts().getEmile());
		 pt.setEndTime(userPart.getPts().getEndTime());
		 pt.setMoney(userPart.getPts().getMoney());
		 pt.setPeopleNum(userPart.getPts().getPeopleNum());
		 pt.setStartTime(userPart.getPts().getStartTime());
		 pt.setOther(userPart.getPts().getOther());
		 pt.setStatus(userPart.getPts().getStatus());
		 
		 
		 newUserPart.setComments(userPart.getComments());
		 newUserPart.setParStatus(userPart.getParStatus());
		 newUserPart.setUspartId(userPart.getUspartId());
		 newUserPart.setApplyNumber(applyNumber);
		 newUserPart.setApplyPassNumber(applyPassNumber);
		 newUserPart.setPts(pt);
		 newUserPart.setUser(login);
		 
		return newUserPart;
		
	}


	
	
	

   //审核职位申请
	public void partTimeAppluAudit(UserPartTimeMod userPartTime,int userPartTimeId) {
		
		
		UserPartTimeMod uptm=studentDao.selectUserPartTimeById(userPartTimeId);
		uptm.setComments(userPartTime.getComments());
		uptm.setParStatus(userPartTime.getParStatus());
		studentDao.partTimeApplyAudit(uptm);
		
		
	}




	public List<UserPartTimeMod> selectMyApplyPartTime(int allUserId) {
		
	   
	  
		List<UserPartTimeMod> newUserPartTimeList=new ArrayList<UserPartTimeMod>();
		List<UserPartTimeMod> userPartTimeList=new ArrayList<UserPartTimeMod>();
		userPartTimeList=studentDao.selectUserPartTimeByAllUserId(allUserId);
		
		//int applyPassNumber=studentDao.countApplyPartTimeNumber(userPartTimeId).size();
		
		for(int i=0;i<userPartTimeList.size();i++){
			 
			PartTimeMod partTime=new PartTimeMod();
		 	UserPartTimeMod userPartTime=new UserPartTimeMod();
			partTime.setJobId(userPartTimeList.get(i).getPts().getJobId());
			partTime.setCompany(userPartTimeList.get(i).getPts().getCompany());
			partTime.setContent(userPartTimeList.get(i).getPts().getContent());
			userPartTime.setPts(partTime);
			//c错误问题，循环出来所有值相同  错误原因为：在循环外面新疆实体
			userPartTime.setUspartId(userPartTimeList.get(i).getUspartId());
			userPartTime.setComments(userPartTimeList.get(i).getComments());
			userPartTime.setParStatus(userPartTimeList.get(i).getParStatus());
			
			newUserPartTimeList.add(userPartTime);
		}
		
		return newUserPartTimeList;
	}

	
	
	
   //返回到学生查看自己的贷款申请信息管理页
	public List<LoadMod> selectMyLoadApply(int allUserId) {
		
		
	//	LoginMod user=studentDao.selectMyLoadApply(allUserId);
		List<AuditsMod> auditList=studentDao.selectAudit(allUserId);
		List<LoadMod> loadList=new ArrayList<LoadMod>();
		
		for(int i=0;i<auditList.size();i++)
		{
		LoadMod load=new LoadMod();
		int audit=auditList.get(i).getAuditId();
		LoadMod loadMod=new LoadMod();
		load=studentDao.selectLoad(audit);
		
		LoadMoneyMod loadMoney=new LoadMoneyMod();
		loadMoney.setLoadMoney(load.getLoadMoney().getLoadMoney());
		
		loadMod.setLoadId(load.getLoadId());
		loadMod.setLoadAmount(load.getLoadAmount());
		loadMod.setLoadTime(load.getLoadTime());
		loadMod.setLoadReason(load.getLoadReason());
		loadMod.setLoadMoney(loadMoney);
		loadMod.setAuditStatus(auditList.get(i).getAudStatus());
		
		loadList.add(loadMod);
		}
		return loadList;
	}

	
	public List<HmenberMod> getHmenber(int allUserId){
		LoginMod loginMod=studentDao.selectStudent(allUserId);
		int  homeId=loginMod.getStu().getHome().getHomeId();
		List<HmenberMod> menberList=studentDao.getHmenber(homeId);
		return menberList;
	}
	
	
	public LoginMod selectStudentById(int allUserId) {
		HomeMod home=new  HomeMod();
		StudentMod student=new StudentMod();
		ClassMod classes=new ClassMod();
		LoginMod newLogin=new LoginMod();
		CollegeMod college=new CollegeMod();
		LoginMod loginMod=studentDao.selectStudent(allUserId);
		
		home.setAddress(loginMod.getStu().getHome().getAddress());
		home.setHphone(loginMod.getStu().getHome().getHphone());
		
		
		student.setAges(loginMod.getStu().getAges());
		student.setResidents(loginMod.getStu().getResidents());
		student.setSchool(loginMod.getStu().getSchool());
		student.setResidents(loginMod.getStu().getResidents());
		student.setSex(loginMod.getStu().getSex());
		student.setSpeciality(loginMod.getStu().getSpeciality());
		student.setStatus(loginMod.getStu().getStatus());
		student.setStudentId(loginMod.getStu().getStudentId());
		student.setUserId(loginMod.getStu().getUserId());
		student.setHome(home);
		
	//	LoginMod login=loginDao.selectUserById(allUserId);
		classes.setClassName(loginMod.getClassId().getClassName());
		classes.setClassId(loginMod.getClassId().getClassId());
		
		college.setColName(loginMod.getClassId().getCollegeId().getColName());
		college.setCollegeId(loginMod.getClassId().getCollegeId().getCollegeId());
		classes.setCollegeId(college);
		
		 newLogin.setClassId(classes);
		 newLogin.setUserAccount(loginMod.getUserAccount());
		 newLogin.setName(loginMod.getName());
		 newLogin.setStu(student);
		 
		return newLogin;
	}

	
	
	
	public HomeMod getHome(int allUserId) {
		int homeId=loginDao.selectUserById(allUserId).getStu().getHome().getHomeId();
	 return	studentDao.getHome(homeId);
	}


	public LoadMod selectLoad(int loadId) {
		
		return studentDao.selectLoadById(loadId);
	}


	public LoadMod selectLoadById(int loadId)
	{
		return studentDao.selectLoadById(loadId);
	}

	
	
	public void setStudentDao(StudentDao studentDao) {
		this.studentDao = studentDao;
	}



	public void setLoginDao(LoginDao loginDao) {
		this.loginDao = loginDao;
	}



	public void setPartTimeDao(PartTimeDao partTimeDao) {
		this.partTimeDao = partTimeDao;
	}
	
	

}
